﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BooksManagermentSystem
{
    public partial class UpdateStudentPwd_form : Form
    {
        public UpdateStudentPwd_form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //表单验证
            string oldpwd = textBox1.Text.Trim();
            if(oldpwd.Length == 0 )
            {
                MessageBox.Show("请输入原密码!");
                textBox1.Focus();
                return;
            }
            string newpwd = textBox2.Text.Trim();
            if(newpwd.Length == 0 )
            {
                MessageBox.Show("请输入新密码!");
                textBox2.Focus();
                return;
            }
            if (newpwd.Length < 6)
            {
                MessageBox.Show("长度起码六位!");
                textBox2.Focus();
                return;
            }

            //修改密码
            string sql = $"update StuInfo set stupwd = '{newpwd}' where stuid = '{Tag.ToString()}' and stupwd ='{oldpwd}'";
            if(DBhelper.NonQuery(sql))
            {
                MessageBox.Show("修改成功！");
                this.Close();
            }
            else
            {
                MessageBox.Show("密码错误！");
                textBox1.Focus();
            }
        }
    }
}
